package cn.est.controller;
import cn.est.pojo.EvaluateDetail;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.EvaluateDetailService;
import cn.est.service.SmsLogService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/evaluateDetail")
public class EvaluateDetailController {

    @Resource
    private EvaluateDetailService evaluateDetailService;

    private Logger logger= LoggerFactory.getLogger(SmsLogController.class);

    @Resource
    private SmsLogService smsLogService;

    @PostMapping(value = "verifyCode")
    public Result verifyCode(String phone,Integer codeType){
        logger.info("发送短信phone：{phone},短信类型：{}",phone,codeType);

        smsLogService.sendMessage(phone,codeType,null);
        Result result = ResultUtils.returnSuccess();
        return result;
    }

    @RequestMapping("/search")
    @ResponseBody
    public Page<EvaluateDetail> searchEvaluateDetail(@RequestParam Map<String,Object> param) {
        Page<EvaluateDetail> evaluateDetailPage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            evaluateDetailPage  = evaluateDetailService.queryEvaluateDetailPageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return evaluateDetailPage;
    }

    @RequestMapping("/saveOrUpdateEvaluateDetail")
    @ResponseBody
    public Result saveOrUpdateEvaluateDetail(EvaluateDetail evaluateDetail){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(evaluateDetail.getId())){
                flag=evaluateDetailService.qdtxAddEvaluateDetail(evaluateDetail);
            }else{
                flag=evaluateDetailService.qdtxModifyEvaluateDetail(evaluateDetail);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getEvaluateDetailById")
    @ResponseBody
    public Result getEvaluateDetailById(Long id){
        Result result= ResultUtils.returnSuccess();
        EvaluateDetail evaluateDetail=null;
        try {
            evaluateDetail=evaluateDetailService.getEvaluateDetailById(id);
            result.setData(evaluateDetail);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemoveEvaluateDetail")
    @ResponseBody
    public Result batchRemoveEvaluateDetail(String ids){
        Integer flag=0;
        try {
            flag=evaluateDetailService.qdtxBatchDeleteEvaluateDetail(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removeEvaluateDetailById")
    @ResponseBody
    public Result removeEvaluateDetailById(Long id){
        Integer flag=0;
        try {
            flag=evaluateDetailService.qdtxDeleteEvaluateDetailById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
